package com.chezhujie.www.service;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.chezhujie.www.core.PropertiesData;
import com.chezhujie.www.domain.Trolepermission;
import com.chezhujie.www.domain.Tsuser;
import com.chezhujie.www.domain.vo.TUser;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by 汤伟杰 on 2017/5/22.
 */
@Service
public class HomeService {

    /**
     * 登录检查
     * @param username
     * @param password
     * @param req
     * @return
     */
    public boolean checkLogin(String username, String password, HttpServletRequest req) {
    	
    	Map<String, Object> param = new HashMap<String, Object>();
    	param.put("username", username);   	
    	Tsuser tsuser = tuserService.getTuserByName(param);
    	if(tsuser==null){
    		return false;
    	}
        String db_username = tsuser.getUsername();
        String db_password = tsuser.getPasswd();
        if(db_username.equals(username)&&db_password.equals(password)){
        	
        	Map<String, Object> param1 = new HashMap<String, Object>();
        	param1.put("userid", tsuser.getUserid());
            Set<Trolepermission>  sets = tuserService.getTuserPer(param1);
        	tsuser.setTrolepermissions(sets);      	
            req.getSession().setAttribute("user",tsuser);
            return true;
        }
        return false;
    }
    
    
	@Resource
	private TuserService tuserService;
	
	
}


     
     
     
     
     
